package edu.task.snake.model.arena;

import edu.task.snake.model.Character;

public class ArenaGrid {
    private Character[][] grid;
    private int width;
    private int height;


    public ArenaGrid(int width, int height) {
        grid = new Character[height][width];
        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                grid[j][i] = null;
            }
        }

        this.width = width;
        this.height = height;
    }


    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    private void checkCoordinate(int width, int height) {
        if (width >= grid.length || width < 0) {
            throw new OutOfAxisXGridException("X not exist " + width);
        }

        if (height >= grid.length || height < 0) {
            throw new OutOfAxixYGridException("Y not exist" + height);
        }
    }

    public void setToArena(int width, int height, Character o) {
        checkCoordinate(width, height);
        grid[width][height] = o;
    }

    public Character getFromArena(int width, int height) {
        checkCoordinate(width, height);
        return grid[width][height];
    }
}
